package com.fastjrun.bms.dao;

import com.fastjrun.bms.entity.SysUser;
import com.fastjrun.bms.entity.SysUserExample;
import com.fastjrun.bms.mapper.SysUserMapper;
import com.fastjrun.bms.mapper.SysUserSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface SysUserDao extends SysUserMapper {
    /**
     * 通过用户名查询用户信息
     * @param username 用户名
     * @return
     */
    @Select({
            "select",
            "id, username, password, is_account_non_expired, is_account_non_locked, is_credentials_non_expired, ",
            "is_enabled, nick_name, mobile, email, create_date, update_date",
            "from sys_user",
            "where username = #{username,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="is_account_non_expired", property="isAccountNonExpired", jdbcType=JdbcType.INTEGER),
            @Result(column="is_account_non_locked", property="isAccountNonLocked", jdbcType=JdbcType.INTEGER),
            @Result(column="is_credentials_non_expired", property="isCredentialsNonExpired", jdbcType=JdbcType.INTEGER),
            @Result(column="is_enabled", property="isEnabled", jdbcType=JdbcType.INTEGER),
            @Result(column="nick_name", property="nickName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
            @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_date", property="updateDate", jdbcType=JdbcType.TIMESTAMP)
    })
    SysUser findByUsername(String username) ;

    /**
     * 修改密码
     * @param userId 用户名
     * @param newPassword 新密码
     * @return
     */
    @Update({
            "update sys_user",
            "set password = #{newPassword,jdbcType=VARCHAR}",
            "where id = #{userId,jdbcType=BIGINT}"
    })
    int modifyPassword(Long userId,String newPassword);
}
